package com.luo.camunda.app.config;

import lombok.extern.slf4j.Slf4j;
import org.camunda.bpm.engine.ProcessEngine;
import org.camunda.bpm.engine.impl.cfg.AbstractProcessEnginePlugin;
import org.camunda.bpm.engine.impl.cfg.ProcessEngineConfigurationImpl;
import org.camunda.bpm.engine.impl.cfg.ProcessEnginePlugin;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import org.springframework.context.annotation.Primary;

@Configuration
@Slf4j
@Primary
public class BpmConfiguration {
    
    @Autowired
    private CustomUuidGenerator customUuidGenerator;
    
    @Bean
    public ProcessEnginePlugin statusPlugin() {
        return new AbstractProcessEnginePlugin() {
            @Override
            public void postInit(ProcessEngineConfigurationImpl processEngineConfiguration) {
                log.warn("post init");
            }
            
            @Override
            public void postProcessEngineBuild(ProcessEngine processEngine) {
                log.warn("post build");
            }
            
            @Override
            public void preInit(ProcessEngineConfigurationImpl processEngineConfiguration) {
                log.warn("pre init");
                //BPM 部分实体未实现 序列化接口 通过redis 缓存时无法序列化存储 调整为 通过监听MQ 清理本地缓存
                //processEngineConfiguration.setCacheFactory(redisBpm);
                
                // 设置缓存容量 默认为 1000 调整为10000
                processEngineConfiguration.setCacheCapacity(10000);
                //使用自定义生成的ID
                processEngineConfiguration.setIdGenerator(customUuidGenerator);
            }
        };
    }
    
}
